home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-06 / an201x.zip / CPUTYPE.ASM < prev    next >
Assembly Source File  |  1991-12-19  |  3KB  |  78 lines

  1. ; Project:      Workstation inventory
  2. ; File:        CPUTYPE.ASM
  3. ; Author:    used by permission of Intel Corporation.
  4. ; Date:        12/15/91
  5. ;
  6. ; Returns:      AX = CPU type 
  7. ;            0086H = 8086 or 8088
  8. ;            0286H = 80286
  9. ;            0386H = 80386SX or 80386DX
  10. ;            0486H = 80486SX or 80486DX
  11. ;
  12. ; Destroys:     upper 16-bits of EAX and ECX on 386/486
  13.  
  14. .386
  15.  
  16. _TEXT   segment word use16 public 'CODE'
  17.  
  18.         assume  cs:_TEXT
  19.  
  20.         public  _cputype
  21. _cputype proc    near
  22.  
  23.         pushf                           ; save flags
  24.         push    bx                      ; save registers used
  25.         push    cx
  26.         pushf                           ; try to clear bits 12-15 of flags
  27.         pop     ax
  28.         and     ax,0fffh
  29.         push    ax                      ; set modified flags
  30.         popf
  31.         pushf
  32.         pop     ax                      ; get flags again
  33.         and     ax,0f000h               ; if bits 12-15 are still       
  34.         cmp     ax,0f000h               ; set, this is 8086/88
  35.         jne     cpu1                    ; jump, not 8086/88
  36.         mov     ax,0086h                ; set AX = 86/88 CPU type
  37.         jmp     cpux                    ; and exit
  38.  
  39. cpu1:   or      ax,0f000h               ; must be 286 or later, 
  40.         push    ax                      ; now try to set bits 12-15
  41.         popf                            ; of CPU flags
  42.         pushf
  43.         pop     ax                      ; if bits 12-15 can't be
  44.         and     ax,0f000h               ; set, this is a 286
  45.         jnz     cpu2                    ; jump, not 80286
  46.         mov     ax,286h                 ; set AX = 286 CPU type
  47.         jmp     cpux                    ; and exit
  48.  
  49. cpu2:   mov     bx,sp                   ; 386 or later, save SP
  50.         and     sp,not 3                ; avoid stack alignment fault
  51.         pushfd                          ; get value of EFLAGS
  52.         pop     eax
  53.         mov     ecx,eax                 ; save copy of EFLAGS 
  54.         xor     eax,40000h              ; flip AC bit in EFLAGS
  55.         push    eax                     ; try and force EFLAGS
  56.         popfd
  57.         pushfd                          ; get back EFLAGS value
  58.         pop     eax
  59.         mov     sp,bx                   ; restore old stack pointer
  60.         xor     eax,ecx                 ; can AC bit be changed?
  61.         jnz     cpu3                    ; no, jump, not a 386
  62.         mov     ax,0386h                ; set AX = 386 CPU type
  63.         jmp     cpux                    ; and exit
  64.  
  65. cpu3:   mov     ax,0486h                ; set AX = 486 CPU type 
  66.  
  67. cpux:   pop     cx                      ; restore registers
  68.         pop     bx
  69.         popf                            ; restore original flags
  70.         ret                             ; return with AX = cpu type
  71.  
  72. _cputype endp
  73.  
  74. _TEXT   ends
  75.  
  76.         end     
  77.  
  78.